import {
  reactive
} from 'vue';
import {
  BasicColumn
} from '/@/components/Table';
import {
  FormSchema
} from '/@/components/Table';
import {
  rules
} from '/@/utils/helper/validator';
import {
  render
} from '/@/utils/common/renderUtils';
import {
  JVxeTypes,
  JVxeColumn
} from '/@/components/jeecg/JVxeTable/types';
import {
  callbackify
} from 'util';

import {
  getUserList
} from '/@/api/common/api';
const awaitList = reactive({
  data: []
})
const getList = async () => {
  awaitList.data = (await getUserList({
    pageNo: 1,
    pageSize: 9999
  })).records
}
getList()
export const productionSchedulingLogColumns: JVxeColumn[] = [{
    title: '编码',
    key: 'code',
    type: JVxeTypes.normal,
    defaultValue: '',
  },
  {
    title: '开始时间',
    key: 'startDate',
    type: JVxeTypes.normal,
  },
  {
    title: '完成时间',
    key: 'finishDate',
    type: JVxeTypes.normal,
  },
  {
    title: '耗时分钟',
    key: 'consumer',
    type: JVxeTypes.normal,
  },
  {
    title: '订单数量',
    key: 'orderCount',
    type: JVxeTypes.normal
  },
  {
    title: '排产结果',
    key: 'status',
    type: JVxeTypes.slot,
    defaultValue: '',
    slotName: "statusSlot",
    // options: [{ value: 0, label: '未启用' }, { value: 1, label: '已启用' }]
    // customValue: () => {
    //   console.log(1);

    // }
  },
  {
    title: '排产错误消息',
    key: 'message',
    type: JVxeTypes.normal,
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '备注',
    key: 'remark',
    type: JVxeTypes.normal,
  },
  // {
  //   title: '操作',
  //   key: 'action',
  //   width: '100px',
  //   fixed: 'right',
  //   align: 'center',
  //   type: JVxeTypes.slot,
  //   slotName: 'action',
  // },
]
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '计划单号',
    align: "center",
    dataIndex: 'schedulingCode',
    width: 160,
  },
  {
    title: '计划名称',
    align: "center",
    dataIndex: 'schedulingName',
    width: 160,
  },
  {
    title: '排产方案',
    align: "center",
    sorter: true,
    width: 120,
    dataIndex: 'productionSchedulingScheme'
  },
  {
    title: '计划员',
    align: "center",
    sorter: true,
    width: 120,
    dataIndex: 'planner'
  },
  {
    title: '是否下发',
    align: "center",
    sorter: true,
    width: 120,
    dataIndex: 'whetherIssue',
    customRender: ({
      text
    }) => {
      return text==1?'是':'否'
    },
  },
  {
    title: '创建时间',
    align: "center",
    sorter: true,
    width: 120,
    dataIndex: 'createTime'
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "计划编码",
    field: "schedulingCode",
    component: 'Input',
    colProps: {
      span: 6
    },
  },
  {
    label: "方案名称",
    field: "productionSchedulingScheme",
    component: 'Input',
    colProps: {
      span: 6
    },
  },
  {
    label: "计划时间",
    field: "plannedTime",
    component: 'DatePicker',
    colProps: {
      span: 6
    },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '计划号',
    field: 'schedulingCode',
    component: 'Input',
    rules: [{
      required: true,
      message: "排产计划号不能为空"
    }],
  }, {
    label: '计划名称',
    field: 'schedulingName',
    component: 'Input',
    rules: [{
      required: true,
      message: "计划名称不能为空"
    }],
  },
  {
    label: '排产方案',
    field: 'productionSchedulingScheme',
    component: 'Input',
    slot: 'productionSchedulingSchemeSlot',
    rules: [{
      required: true,
      message: "请选择排产方案"
    }],
  },
  {
    label: '排产方案Id',
    field: 'productionSchedulingSchemeId',
    component: 'Input',
    show: false
  },
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
];
//子表单数据
//子表表格配置
export const psPrePlanningSchedulingOrderContentColumns: JVxeColumn[] = [{
    title: '来源单据id',
    key: 'srcDocId',
    type: JVxeTypes.hidden,
  },
  {
    title: '来源类型',
    key: 'srcDocType',
    type: JVxeTypes.slot,
    slotName: "srcDocTypeSlot",
    placeholder: '请输入${title}',
    width: "120px",
    defaultValue: '',
  },
  {
    title: '来源单号',
    key: 'srcDocNo',
    type: JVxeTypes.normal,
    width: "160px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '来源单行号',
    key: 'srcDocLineNo',
    type: JVxeTypes.normal,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '产品编码',
    key: 'productCode',
    type: JVxeTypes.normal,
    width: "160px",
    slotName: 'productNameSlot',
    placeholder: '请选择${title}',
    defaultValue: '',
  },
  {
    title: '产品名称',
    key: 'productName',
    width: "160px",
    type: JVxeTypes.normal,
    placeholder: '请输入${title}',
  },
  {
    title: '交期',
    key: 'orderDeliveryDate',
    type: JVxeTypes.normal,
    width: '140px',
  },
  {
    title: '订单号',
    key: 'orderNo',
    type: JVxeTypes.normal,
    width: "160px",
    placeholder: '请输入${title}',
    defaultValue: '',
    dynamicDisabled: true
  },
  {
    title: '订单行号',
    key: 'orderRowNo',
    type: JVxeTypes.normal,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: '',
    dynamicDisabled: true
  },
  {
    title: '订单数量',
    key: 'orderQuantity',
    type: JVxeTypes.normal,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: '',
    dynamicDisabled: true
  },
  {
    title: '排产数量',
    key: 'actualProductionScheduling',
    type: JVxeTypes.normal,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '操作',
    key: 'action',
    fixed: 'right',
    align: 'center',
    type: JVxeTypes.slot,
    slotName: 'action',
    width: "120px"
  },

]
export const psPlanningSchedulingAvailableResourcesColumns: JVxeColumn[] = [

  {
    title: '排产工作台id',
    key: 'schedulingWorkbenchId',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '资源组id',
    key: 'resourceGroupId',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '资源组',
    key: 'resourceGroup',
    type: JVxeTypes.input,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '资源分类Id',
    key: 'resourceClassId',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '资源分类',
    key: 'resourceClassification',
    type: JVxeTypes.input,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '资源编码',
    key: 'resourceCoding',
    type: JVxeTypes.input,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '资源名称',
    key: 'resourceName',
    type: JVxeTypes.input,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '资源规格',
    key: 'resourceSpecification',
    type: JVxeTypes.input,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '车间自编码',
    key: 'workshopSelfCoding',
    type: JVxeTypes.input,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '数量',
    key: 'quantity',
    type: JVxeTypes.inputNumber,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '数量单位id',
    key: 'quantityUnitId',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '数量单位',
    key: 'quantityUnit',
    type: JVxeTypes.input,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '是否专用',
    key: 'isDedicated',
    type: JVxeTypes.select,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: 1,
    options: [{
      label: '是',
      value: 1
    }, {
      label: '否',
      value: 1
    }]
  },
  {
    title: '是否上机',
    key: 'isComputer',
    type: JVxeTypes.select,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: 1,
    options: [{
      label: '是',
      value: 1
    }, {
      label: '否',
      value: 1
    }]
  },
  {
    title: '不参与排产',
    key: 'isProductionScheduling',
    type: JVxeTypes.select,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: 1,
    options: [{
      label: '是',
      value: 1
    }, {
      label: '否',
      value: 1
    }]
  },
  {
    title: '第三方编码',
    key: 'thirdPartyCode',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '备注',
    key: 'remark',
    type: JVxeTypes.input,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
]
export const psPlanningSchedulingProcessDetailColumns: JVxeColumn[] = [{
    title: '排产工作台id',
    key: 'schedulingWorkbenchId',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '订单编码',
    key: 'orderCode',
    type: JVxeTypes.slot,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
    slotName: 'orderSlot'
  },
  {
    title: '产品id',
    key: 'productId',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '产品名称',
    key: 'productName',
    type: JVxeTypes.normal,
    width: "200px",
    placeholder: '请输入${title}',
  },
  {
    title: '产品规格',
    key: 'productStandard',
    type: JVxeTypes.input,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '订单数量',
    key: 'orderQuantity',
    type: JVxeTypes.inputNumber,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '订单交期',
    key: 'orderDeliveryDate',
    type: JVxeTypes.date,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '上期末排量',
    key: 'lastEndDischarge',
    type: JVxeTypes.inputNumber,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '库存',
    key: 'inventory',
    type: JVxeTypes.inputNumber,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '需求',
    key: 'demand',
    type: JVxeTypes.inputNumber,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '需徘产数',
    key: 'productionScheduledNumber',
    type: JVxeTypes.inputNumber,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '分配资源数',
    key: 'allocatedResourcesNumber',
    type: JVxeTypes.inputNumber,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '单位资源产能',
    key: 'capacityPerUnitResources',
    type: JVxeTypes.inputNumber,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '总产能',
    key: 'totalCapacity',
    type: JVxeTypes.inputNumber,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '分配产能',
    key: 'allocatedCapacity',
    type: JVxeTypes.inputNumber,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '耗用时长',
    key: 'consumptionTime',
    type: JVxeTypes.inputNumber,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '投放日期',
    key: 'releaseDate',
    type: JVxeTypes.date,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '排产开始时间',
    key: 'schedulingStartTime',
    type: JVxeTypes.date,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
    validateRules: [{
      handler({
        cellValue,
        row
      }, callback, target) {
        let startTime = new Date(cellValue).getTime();
        let endTime = new Date(row.estimatedCompletionTime).getTime();
        if (startTime > endTime) {
          callback(false, '${title}不能比推算完成时间大')
        } else {
          callback(true);
        }
      }
    }],
  },
  {
    title: '推算完成时间',
    key: 'estimatedCompletionTime',
    type: JVxeTypes.date,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
    validateRules: [{
      handler({
        cellValue,
        row
      }, callback, target) {

        let startTime = new Date(row.schedulingStartTime).getTime();
        let endTime = new Date(cellValue).getTime();
        if (startTime > endTime) {
          callback(false, '${title}不能比排产开始时间小')
        } else {
          callback(true);
        }
      }
    }],
  },
  {
    title: '第三方编码',
    key: 'thirdPartyCode',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '备注',
    key: 'remark',
    type: JVxeTypes.input,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
]
// 模拟排产结果列表
export const simulatedResultColumns: JVxeColumn[] = [{
    title: '订单编号',
    key: 'orderNumber',
    type: JVxeTypes.normal,
    width: "140px",
  },
  {
    title: '行号',
    key: 'rowNum',
    type: JVxeTypes.normal,
    width: "80px",
  },
  {
    title: '资源名称',
    key: 'resourceName',
    type: JVxeTypes.normal,
    width: "140px",
  },
  {
    title: '产品编码',
    key: 'materialCode',
    type: JVxeTypes.normal,
    width: "140px",
  },
  {
    title: '产品名称',
    key: 'materialName',
    type: JVxeTypes.normal,
    width: "120px",
  },
  {
    title: '图号',
    key: 'drawingNo',
    type: JVxeTypes.normal,
    width: "100px",
  },
  {
    title: '订单数量',
    key: 'quantity',
    type: JVxeTypes.normal,
    width: "120px",
  },
  {
    title: '订单交期',
    key: 'deliveryDate',
    type: JVxeTypes.normal,
    width: "120px",
  },
  {
    title: '生产单号',
    key: 'productOrderCode',
    type: JVxeTypes.normal,
    width: "140px",
  },
  {
    title: '上线日期',
    key: 'lineDate',
    type: JVxeTypes.normal,
    width: "120px",
  },
  {
    title: '是否能安全交货',
    key: 'isCompleted',
    type: JVxeTypes.normal,
    width: "140px",
  },
  {
    title: '工艺',
    key: 'process',
    type: JVxeTypes.normal,
    width: "100px",
  },
  {
    title: '上期未排量',
    key: 'previousUnscheduled',
    type: JVxeTypes.normal,
    width: "140px",
  },
  {
    title: '库存',
    key: 'inventory',
    type: JVxeTypes.normal,
    width: "80px",
  },
  {
    title: '排产数量',
    key: 'requiredProduction',
    type: JVxeTypes.normal,
    width: "120px",
  },
  {
    title: '计划员',
    key: 'createBy',
    type: JVxeTypes.normal,
    width: "120px",
  },
]

// 子表编辑  对应的form数据
export const psPlanningSchedulingOrderContentFormSchema: FormSchema[] = [{
  label: '计划订单',
  field: 'srcDocId',
  component: 'Input',
  show: false
}, {
  label: '来源订单',
  field: 'srcDocNo',
  component: 'Input',
  dynamicDisabled: true
}, {
  label: '行号',
  field: 'srcDocLineNo',
  component: 'Input',
  dynamicDisabled: true
}, {
  label: '产品编码',
  field: 'productCode',
  component: 'Input',
  dynamicDisabled: true
}, {
  label: '产品名称',
  field: 'productName',
  component: 'Input',
  dynamicDisabled: true
}, {
  label: '交期',
  field: 'orderDeliveryDate',
  component: 'DatePicker',
  componentProps: {
    valueFormat: 'YYYY-MM-DD',
    getPopupContainer: () => document.body,
  },
}, {
  label: '订单数量',
  field: 'orderQuantity',
  component: 'InputNumber',
  dynamicDisabled: true
}, {
  label: '上期未排量',
  field: 'lastEndDischarge',
  component: 'InputNumber',
  dynamicDisabled: true

}, {
  label: '排产数量',
  field: 'actualProductionScheduling',
  component: 'Input',
  dynamicRules: ({
    model,
    schema
  }) => {
    return [{
        required: true,
        message: '本次需排产数必填!'
      },
      {
        pattern: /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/,
        message: '本次需排产数必须是大于0的数字'
      }
    ];
  },
}, ]
/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
